// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store/';
import './assets/js/public/hotcss';
import Utils from './assets/js/public/utils/Utils';
import Modulation from './assets/js/public/modulation/index';
import Format from './assets/js/public/colorFormat/index';
import Filters from './assets/js/public/filters/filter';
import Api from './api'
// import Mint from 'mint-ui';
// import {Button, Swipe, SwipeItem, Loadmore, InfiniteScroll, Field, Picker, TabContainer, TabContainerItem, Spinner, Popup, Range} from 'mint-ui';
import VueClipboard from 'vue-clipboard2';
import scroll from 'vue-seamless-scroll'
// import FastClick from 'fastclick';
// import {Loading} from './components/UI/loading/index';
import iView from 'iView';
import {Carousel} from 'iview';
import QRCode from 'qrcode';
import 'iview/dist/styles/iview.css';
/*引入移动端手势库*/
import directives from './directives/touch'

directives(Vue);


Vue.config.productionTip = false;
// simple history management
const history = window.sessionStorage;
let historyCount = history.getItem('count') * 1;
// const router = new VueRouter({
//   mode: 'history',
//   base: __dirname,
//   routes
// });
router.beforeEach(function (to, from, next) {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  const toIndex = history.getItem(to.path);
  const fromIndex = history.getItem(from.path);
  if (toIndex) {
    if (!fromIndex || parseInt(toIndex, 10) > parseInt(fromIndex, 10) || (toIndex === '0' && fromIndex === '0')) {
      store.commit('UPDATE_DIRECTION', {direction: 'forward'})
    } else {
      store.commit('UPDATE_DIRECTION', {direction: 'reverse'})
    }
  } else {
    ++historyCount;
    history.setItem('count', historyCount);
    to.path !== '/' && history.setItem(to.path, historyCount);
    store.commit('UPDATE_DIRECTION', {direction: 'forward'})
  }
  if (/\/http/.test(to.path)) {
    let url = to.path.split('http')[1];
    window.location.href = `http${url}`
  } else {
    next()
  }
});
Vue.prototype._Util = Utils;
Vue.prototype._Modulation = Modulation;
Vue.prototype._Format = Format;
Vue.prototype._Api = Api;
Vue.prototype._Filter = Filters;
Vue.prototype._QRCode = QRCode;
Utils.init();
Vue.use(iView);
Vue.use(scroll);
Vue.use(VueClipboard);
// Vue.use(QRCode);
Vue.component('Carousel', Carousel);

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {App}
});
